package com.sj.common.dto.comment;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.sj.common.dto.user.UserDto;
import com.sj.entity.Article;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: xiaoqi
 * Date: 2022-03-17
 * Time: 上午 10:42
 * Description: 评论返回数据模型
 *
 * @author xiaoqi
 * @since 2022-03-17
 */
@Data
@ApiModel("评论返回数据类型")
@NoArgsConstructor
@AllArgsConstructor
public class CommentDto implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("评论id 自增长")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("文章id")
    private Integer articleId;

    @ApiModelProperty("评论内容")
    private String content;

    @ApiModelProperty("评论类型 回复（answer） 评论 （comment）")
    private String type;

    @ApiModelProperty("父评论id 如果该评论或回复为最高及评论 则为0 否则为父评论id")
    private Integer parentId;

    @ApiModelProperty("父评论")
    private CommentDto parent;

    @ApiModelProperty("文章信息")
    private Article article;

    @ApiModelProperty("用户信息")
    private UserDto user;

    @ApiModelProperty("评论的回复")
    private List<CommentDto> childList;

    @ApiModelProperty("点赞数量")
    private Long praiseNum;

    @ApiModelProperty("是否删除 1 删除 0 未删除")
    @TableLogic
    private Boolean del;

    @ApiModelProperty("创建时间")
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;

    @ApiModelProperty("更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime updateTime;
}